<?php
	$page_title="show online status";
	include('inc/header.php');
?>
	<h1 align=center>Problem Status List<h1>
<?php
	require_once('../db/dbinfo.php');
	$sql="select rid ,pid ,	res ,mem ,runtime ,lang ,codelen ,subtime from status order by rid desc";
   	$ret= mysqli_query($dbc,$sql);
	$tot= mysqli_num_rows($ret);
	$display =10;
	$totp=(int)($tot/$display)+1;
	if (isset($_REQUEST['page'])&&is_numeric($_REQUEST['page'])){
		$page=$_REQUEST['page'];
		if ($page>$totp){
			$page=$totp;
		}
	}else{
		$page=1;
	}
	$st=($page-1)*$display;
	$ed=$st+$display;
	$sql="select rid ,pid ,	res ,mem ,runtime ,lang ,codelen ,subtime from status order by rid desc limit $st,$ed";
	$ret=mysqli_query($dbc,$sql);
?>
	<table align="center" cellspacing="0" cellpadding="5" width="75%" >
	<tr>
		<td>run id</td>
		<td>problem id</td>
		<td>result</td>
		<td>memery used</td>
		<td>time used</td>
		<td>languge</td>
		<td>code length</td>
		<td>submit time</td>
	</tr>
<?php
	$bg="#eeeeee";
	while ($row=mysqli_fetch_array($ret)){
		$bg=($bg=="#eeeeee"?"#ffffff":"#eeeeee");
		echo "<tr bgcolor='$bg'>";
			for ($i=0;$i<8;$i++){
				echo "<td>$row[$i]</td>\n";
			}
		echo "</tr>\n";
	}
	echo "</table>\n";
	//i fell some thing wrong;
	$pdis=5;
	$pst=((int)($page/$pdis))*$pdis+1;
	$ped=$pst+$pdis;
	if ($ped>$totp)
		$ped=$totp;
	for ($i=$pst;$i<=$ped;$i++){
		$self=$_SERVER['PHP_SELF'];
		echo "<a href='$self?page=$i'>$i</a>\n";
	}
	$next=$page+1;
	echo "<a href='$self?page=$next'>Next</a>";
?>
<?php 
	include('inc/footer.php');
?>
